package com.hp.goods_service.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hp.common_api.entity.SpuDetail;
import com.hp.goods_service.service.ISpuDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * Spu详情的控制器
 */
@RestController
public class SpuDetailController {

    @Autowired
    private ISpuDetailService spuDetailService;

    /**
     * 通过SpuID查询下面所有的SKU
     * @return
     */
    @GetMapping("/spuDetail/{spuId}")
    public ResponseEntity<SpuDetail> getSpuDetailBySpuId(
            @PathVariable Long spuId){
        SpuDetail spuDetail = spuDetailService.getOne(new QueryWrapper<SpuDetail>().lambda().eq(SpuDetail::getSpuId, spuId));
        return ResponseEntity.ok(spuDetail);
    }
}
